package com.example.food_contract_system.controller;

import com.example.food_contract_system.service.OrderService;
import com.example.food_contract_system.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiHaoyang
 * @date 2023/7/12  9:54
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单创建
     * @param aId
     * @param cId
     * @param productList
     * @return
     */
    @PostMapping("/insertOrder/{aId}/{cId}")
    public R insertOrder(@PathVariable("aId") String aId,
                         @PathVariable("cId") String cId,
                         @RequestBody String productList){
        R result = orderService.insertOrder(aId,cId,productList);
        return result;
    }

    /**
     * 获取每个经销商的订单列表
     * @param aId
     * @return
     */
    @GetMapping("/getOrderListByUser/{aId}")
    public R getOrderListByUser(@PathVariable("aId") String aId){
        R result = orderService.getOrderListByUser(aId);
        return result;
    }

    /**
     * 根据订单id获取每个订单的货物详情
     * @param oId
     * @return
     */
    @GetMapping("/getOrderDetail/{oId}")
    public R getOrderDetail(@PathVariable("oId") String oId){
        R result = orderService.getOrderDetail(oId);
        return result;
    }

    @GetMapping("/pay/{oId}/{aId}")
    public R pay(@PathVariable("oId") String oId,
                 @PathVariable("aId") String aId){
        R result = orderService.pay(oId,aId);
        return result;
    }

    @GetMapping("/deleteOrder/{oId}")
    public R deleteOrder(@PathVariable("oId")String oId){
        R result = orderService.deleteOrder(oId);
        return result;
    }
}
